package cn.tellsea.service.impl;

import cn.tellsea.entity.AjaxResult;
import cn.tellsea.entity.BizStorage;
import cn.tellsea.mapper.BizStorageMapper;
import cn.tellsea.service.IBizStorageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 库存表 服务实现类
 * </p>
 *
 * @author Tellsea
 * @since 2021-12-31
 */
@Slf4j
@Service
public class BizStorageServiceImpl extends ServiceImpl<BizStorageMapper, BizStorage> implements IBizStorageService {

    @Override
    public AjaxResult decrease(Long productId, Integer count) {
        log.info("------->中扣减库存开始");
        BizStorage storage = baseMapper.selectById(productId);
        storage.setUsed(storage.getUsed() + count);
        storage.setResidue(storage.getResidue() - count);
        baseMapper.updateById(storage);
        log.info("------->中扣减库存结束");
        return AjaxResult.success("扣减库存成功");
    }
}
